# -*- coding:utf-8 -*-
import csv
import pymysql
'''
处理食物功效表，提取食物和元素进行数据拼接形成固定的食物功效询问句式:
1、脂肪肝可以吃什么
2、脂肪肝如何饮食
3、脂肪肝饮食要注意什么
4、脂肪肝的饮食禁忌
5、xx应该怎么吃
6、xx可以怎么吃
7、xx怎么饮食
8、xx怎么通过饮食预防
9、xx怎么吃
10、xx吃什么好
11、xx要注意什么
12、xx怎么预防
13、xx怎么改善
14、
15、
'''

class TestNum():

    def numreorganization(self):

        # food_num = []
        # food_first = '吃'
        # food_second = '可以补充'
        # food_third = '吗'
        # # 连接本地数据库
        # conn = pymysql.connect(host='localhost',
        #                        port=3306,
        #                        user='root',
        #                        password='111111',
        #                        db='test', charset='utf8')
        #
        # # 通过获取到的数据库连接conn下的cursor()方法来创建游标
        # cur = conn.cursor()
        #
        # # 创建数据库
        # '''ENGINE=INNODB 表示将数据库的引擎设置为InnoDB,从MySQL 5.6开始默认使用该引擎。
        #
        # AUTO_INCREMENT=10 表示自动增长的起始值为10
        #
        # DEFAULT CHARSET=utf8表示设置数据库的默认字符集为utf8
        # '''
        # cur.execute("DROP TABLE IF EXISTS food_effect")
        # conn.commit()
        # create_db = '''create table food_effect(name_id INT NOT NULL AUTO_INCREMENT,name varchar(300),PRIMARY KEY(name_id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin'''
        # cur.execute(create_db)  # 执行创建表语句
        # conn.commit()

        # 读取csv文件,SymptomsPrecautions.csv+semantic.csv;semantic2.csv+SymptomsPrecautions.csv

        food_list = []

        with open("E:\\test\\HB\\semantic2.csv",'r') as f1,\
                open('E:\\test\\HB\\SymptomsPrecautions.csv', 'r')as f2:
            # for l1 in f1:
            #     l2 = f2.readline()
            #     print(l2)
            #     print(type(l2))
            # f11=csv.reader(f1)
            # f22 = csv.reader(f2)
            f11 = f1.readlines()
            f22 = f2.readlines()
            print(f11)
            print(f22)
            print(type(f11))

            print(type(f22))
            for i in range(len(f11)):
                name = f11[i]

                print(name)
                for m in range(len(f22)):
                    # m1 = f2.readline()
                    # list -->str

                    food_quanty = f22[m]
                    print(type(food_quanty))
                    # name = "".join(l1)
                    quanty = "".join(food_quanty)
                    s =  name + quanty
                    s_food = s.replace("\n","")
                    print(food_quanty)
                    print("拼接的字符串是:"+ s_food)

                    food_list.append(s_food)
                    print(food_list)

            with open('E:\\test\\HB\\askCondition2.csv', 'a') as f3:
                for k in food_list:
                    f3.write(k)
                    f3.write("\n")
                f3.close()




                    # f3.write(s)
                    # f3.write('\n')
                    # f3.close()
                    # 执行insert
            #         insert_db = "insert into food_effect(name) values(%s)"
            #         cur.executemany(insert_db, s_food_list_new)  # 执行高效插入
            #         conn.commit()
            #
            # # 关闭连接
            # if cur:
            #     cur.close()
            # if conn:
            #     conn.close()

                    # f2.seek(0)

                # l1 = f1.readline()
                    # f2.seek(0,0)
        # f3.close()
        f2.close()


        f1.close()
















if __name__ == '__main__':
    tn = TestNum()
    tn.numreorganization()